/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbo;

import java.util.Arrays;
import java.util.Vector;

/**
 *
 * @author bi
 */
public class Squad implements Comparable<Squad> {

    protected String name;
    public Faction faction;
    protected float cost;
    protected int health;
    protected int armor;
    protected int size;
    private Vector<String> skill;

    public Squad(String name, Faction faction, float cost, int health, int armor, int size, String skill) {
        this.name = name;
        this.faction = faction;
        this.cost = cost;
        this.health = health;
        this.armor = armor;
        this.size = size;

        this.skill = new Vector<String>();
        String[] skillList = skill.split(";");
        this.skill.addAll(Arrays.asList(skillList));
    }

    public Squad(String name) {
        this.name = name;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the cost
     */
    public float getCost() {
        return cost;
    }

    /**
     * @return the health
     */
    public int getHealth() {
        return health;
    }

    /**
     * @return the armor
     */
    public int getArmor() {
        return armor;
    }

    /**
     * @return the size
     */
    public int getSize() {
        return size;
    }

    /**
     * @return the skill
     */
    public boolean hasSkill(String skillName) {
        return getSkill().contains(skillName);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass().equals(this.getClass())) {
            if (this.hashCode() == obj.hashCode()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }

    public int compareTo(Squad squad) {
        int result = (int) Math.round(this.cost - squad.getCost());

        if (result < 0) {
            return -1;
        } else if (result == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * @return the skill
     */
    public String getSkill() {
        String returnString = "";
        for (int i = 0; i < skill.size(); i++) {
            returnString += skill.get(i);
            if (i != skill.size() - 1) {
                returnString += ",";
            }
        }
        return returnString;
    }

    public boolean addSkill(String skillName) {
        return skill.add(skillName);
    }
}
